package com.zadetk.helpyou.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.Toast;

import com.zadetk.helpyou.R;
import com.zadetk.helpyou.activities.PublishServiceActivity;
import com.zadetk.helpyou.other.Const;
import com.zadetk.helpyou.view.NoScrollView;

import java.util.ArrayList;
import java.util.HashMap;

public class ListViewAdapter extends BaseAdapter {
	
	 private ArrayList<ArrayList<HashMap<String, Object>>> mList;
	 private Context mContext;
	 private GridViewAdapter gridViewAdapter;

	  public ListViewAdapter(ArrayList<ArrayList<HashMap<String, Object>>> mList, Context mContext) {
	    super();
	    this.mList = mList;
	    this.mContext = mContext;
	  }


	  @Override
	  public int getCount() {
	    if (mList == null) {
	      return 0;
	    } else {
	      return this.mList.size();
	    }
	  }

	  @Override
	  public Object getItem(int position) {
	    if (mList == null) {
	      return null;
	    } else {
	      return this.mList.get(position);
	    }
	  }

	  @Override
	  public long getItemId(int position) {
	    return position;
	  }

	  @Override
	  public View getView(int position, View convertView, ViewGroup parent) {
	    ViewHolder holder = null;
	    if (convertView == null) {
	      holder = new ViewHolder();			
	      convertView = LayoutInflater.from(this.mContext).inflate(R.layout.layout_listview, null, false);
	     
	      holder.gridView = (NoScrollView) convertView.findViewById(R.id.fixed_gridView);
	      convertView.setTag(holder);
	    } else {
	      holder = (ViewHolder) convertView.getTag();
	    }
	    
	    
	    if (this.mList != null) {
	      if (holder.gridView != null) {
	        ArrayList<HashMap<String, Object>> arrayListForEveryGridView = this.mList.get(position);
	         gridViewAdapter=new GridViewAdapter(mContext, arrayListForEveryGridView);
	        holder.gridView.setAdapter(gridViewAdapter);
			  holder.gridView.setClickable(false);
			  holder.gridView.setPressed(false);
			  holder.gridView.setEnabled(false);

	      }
	    }
	    return convertView;
	  }


	private class ViewHolder {
		NoScrollView gridView;
	}
}
